﻿package mortal.game.view.copy.worldBoss.worldBossEnter
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import frEngine.render.layer.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.game.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.tileList.*;
    import mortal.game.view.guide.*;
    import mortal.mvc.core.*;

    public class WorldSmallBossCellRenderer extends G3DCellRenderer
    {
        protected var _worldBoss:TWorldBoss;
        protected var alphaBg:ScaleBitmap;
        protected var tfName:GTextFiled;
        protected var tfRefreshTime:SecTimerView;
        protected var tfPos:GTextFiled;
        protected var btnFly:GLoadedButton;
        protected var imgBeKilled:GImageBitmap;
        private var _t:int;

        public function WorldSmallBossCellRenderer()
        {
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:BossInfo = null;
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            var _loc_5:String = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            super.data = param1;
            this._worldBoss = param1 as TWorldBoss;
            if (!this.alphaBg)
            {
                this.alphaBg = UIFactory.bg(0, 0, 220, 232, this, BitmapDataConst.AlphaBMD);
                _loc_2 = BossConfig.instance.getInfoByCode(this._worldBoss.bossCode);
                bg = UIFactory.gImageBitmap("smallBossBg.png", 0, 0, null, this.onBgCompl);
                this.tfName = UIFactory.gTextField("", 13, 2, 192, 30, this, GlobalStyle.textFormatBai.setSize(15).center());
                this.tfRefreshTime = UIFactory.secTimeView(Language.getString(21463), 30, 26, 190, 22, this, GlobalStyle.textFormatBai);
                this.tfPos = UIFactory.gTextField("", 40, 208, -1, 30, this, GlobalStyle.textFormatHuang2.setSize(12).center());
                this.tfPos.autoSize = TextFieldAutoSize.LEFT;
                this.btnFly = UIFactory.gLoadedButton(ImagesConst.MapBtnFlyBoot_upSkin, this.tfPos.x + this.tfPos.width, 208, 16, 18, this);
                this.imgBeKilled = UIFactory.gImageBitmap("smallBossKilled.png", 15, 95, this);
                this.imgBeKilled.visible = false;
                this.tfName.htmlText = Language.getStringByParam(21464, _loc_2.level, _loc_2.name);
                _loc_3 = this._worldBoss.movePoint.split("#");
                _loc_4 = _loc_3[0];
                _loc_5 = GameMapConfig.instance.getMapInfo(_loc_4).name;
                if (_loc_3.length >= 3)
                {
                    _loc_6 = _loc_3[1];
                    _loc_7 = _loc_3[2];
                    this.tfPos.htmlText = "<u><a href=\'event:1\'><font color = \'#D36a01\'>" + _loc_5 + "</font><font color = \'#06F005\'>[" + _loc_6 + "," + _loc_7 + "]</font></a></u>";
                }
                else
                {
                    this.tfPos.htmlText = Language.getStringByParam(21465, _loc_5);
                    this.btnFly.visible = false;
                }
                this.btnFly.configEventListener(MouseEvent.CLICK, this.onClickFly);
                this.tfPos.configEventListener(TextEvent.LINK, this.onLink);
            }
            this.updateBossStat();
            NetDispatcher.addCmdListener(ServerCommand.WorldBossStatChange, this.updateBossStat);
            this.toolTipData = this._worldBoss;
            this.tfRefreshTime.timeOutHandler = this.updateNextRefreshStr;
            this.updateNextRefreshStr();
            return;
        }// end function

        protected function updateBossStat(param1 = null) : void
        {
            var _loc_2:* = Cache.instance.copy.worldBoss.getBossIsDeath(this._worldBoss.bossCode);
            this.imgBeKilled.visible = _loc_2;
            return;
        }// end function

        protected function onLink(event:TextEvent) : void
        {
            var _loc_2:* = this._worldBoss.movePoint.split("#");
            var _loc_3:* = _loc_2[0];
            var _loc_4:* = _loc_2[1];
            var _loc_5:* = _loc_2[2];
            var _loc_6:* = new Point(_loc_4, _loc_5);
            GuideEffect.isShowPath = true;
            AIManager.onAIControl(AIType.GoToOtherMap, Game.mapInfo.mapId, _loc_3, _loc_6);
            return;
        }// end function

        protected function onClickFly(event:MouseEvent) : void
        {
            var _loc_2:* = this._worldBoss.flyPoint.split("#");
            var _loc_3:* = _loc_2[0];
            var _loc_4:* = _loc_2[1];
            var _loc_5:* = _loc_2[2];
            var _loc_6:* = new SPassTo();
            _loc_6.mapId = _loc_3;
            var _loc_7:* = new SPoint();
            _loc_7.x = _loc_4;
            _loc_7.y = _loc_5;
            _loc_6.toPoint = _loc_7;
            Dispatcher.dispatchEvent(new DataEvent(EventName.FlyBoot, _loc_6));
            return;
        }// end function

        protected function getRefreshTimes() : Array
        {
            return ["9:00", "12:00", "15:00", "18:00", "21:00", "24:00"];
        }// end function

        private function updateNextRefreshStr() : void
        {
            var _loc_5:String = null;
            var _loc_6:int = 0;
            var _loc_8:String = null;
            var _loc_9:Array = null;
            var _loc_10:int = 0;
            var _loc_11:int = 0;
            var _loc_1:* = this.getRefreshTimes();
            var _loc_2:* = ClockManager.instance.nowDate.hours;
            var _loc_3:* = ClockManager.instance.nowDate.minutes;
            var _loc_4:* = ClockManager.instance.nowDate.seconds;
            var _loc_7:int = 0;
            while (_loc_7 < _loc_1.length)
            {
                
                _loc_8 = _loc_1[_loc_7];
                _loc_9 = _loc_8.split(":");
                _loc_10 = int(_loc_9[0]);
                _loc_11 = int(_loc_9[1]);
                if (_loc_10 > _loc_2 || _loc_10 == _loc_2 && _loc_11 > _loc_3)
                {
                    _loc_5 = _loc_1[_loc_7];
                    _loc_6 = (_loc_10 - _loc_2) * 3600 + (_loc_11 - _loc_3) * 60 - _loc_4;
                    break;
                }
                _loc_7++;
            }
            if (!_loc_5)
            {
                _loc_5 = _loc_1[0];
                _loc_6 = (24 - _loc_2) * 3600 + -_loc_3 * 60 - _loc_4;
            }
            this.tfRefreshTime.setLeftTime(_loc_6);
            return;
        }// end function

        protected function onBgCompl() : void
        {
            isResCompl = true;
            this._t = setTimeout(this.add3DModel, 50);
            return;
        }// end function

        override protected function add3DModel() : void
        {
            var _loc_1:Point = null;
            var _loc_2:BossInfo = null;
            var _loc_3:String = null;
            var _loc_4:String = null;
            var _loc_5:String = null;
            if (this.canAdd3DModel)
            {
                super.add3DModel();
                _loc_1 = this.bgPos;
                itemBg = new Img2D(null, bg.bitmapData, new Rectangle(0, 0, bg.width, bg.height), true);
                itemBg.x = _loc_1.x;
                itemBg.y = _loc_1.y;
                _loc_2 = BossConfig.instance.getInfoByCode(this._worldBoss.bossCode);
                _loc_3 = _loc_2.mesh + ".md5mesh";
                _loc_4 = _loc_2.texture;
                _loc_5 = _loc_2.bone + ".skeleton";
                bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
                bodyPlayer.changeAction(ActionName.Stand);
                bodyPlayer.selectEnabled = false;
                bodyPlayer.play();
                bodyPlayer.scaleValue = this._worldBoss.bossScale * 1 / 100;
                bodyPlayer.setRotation(0, 0, 0);
                bodyPlayer.load(_loc_3, _loc_5, _loc_4, rect3d.renderList);
                rect3d.addObject3d(bodyPlayer, _loc_1.x + 105, _loc_1.y + 165);
                rect3d.addImg(itemBg, Layer3DManager.BackGroudEffectLayer);
                bodyPlayer.rotationY = this._worldBoss.defaultRotate;
                this.btnFly.x = this.tfPos.x + this.tfPos.width;
                this.btnFly.drawNow();
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._worldBoss = null;
            this.alphaBg.dispose();
            this.alphaBg = null;
            this.tfName.dispose();
            this.tfName = null;
            this.tfRefreshTime.dispose();
            this.tfRefreshTime = null;
            this.tfPos.dispose();
            this.tfPos = null;
            this.btnFly.dispose();
            this.btnFly = null;
            this.imgBeKilled.dispose();
            this.imgBeKilled = null;
            if (this._t)
            {
                clearTimeout(this._t);
                this._t = 0;
            }
            NetDispatcher.removeCmdListener(ServerCommand.WorldBossStatChange, this.updateBossStat);
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
